<?php
declare (strict_types=1);

namespace middleware;

use app\admin\service\base\JwtService;

/**
 * 不需要的登录
 */
class NoAuthMiddleware
{

    public function handle($request, \Closure $next, string $name = '')
    {
        //header头信息获取登录access_token
        $access_token = $request->header('Authorization') ?: $request->header('access_token') ?: $request->param('Authorization');
        //是否存在token
        if ($access_token) {
            //解析access_token数据信息
            $vfRes = JwtService::vfAccessToken($access_token);
            if ($vfRes['bool']) {
                //定义用户id常量
                define('WS_USER_ID', $vfRes['data']);
            } else {
                define('WS_USER_ID', 0);
            }
        } else {
            define('WS_USER_ID', 0);
        }
        return $next($request);
    }


}